<!DOCTYPE html>
<html>
<head>
    <title></title>
    
</head>
<body>
    
</body>
    <script>
        //onmousedown   按下按键触发
        // document.onkeydown = function(en){
        //     document.body.style.backgroundColor = "#f90";
        //     console.log(en.keyCode);
        // }

        //onmouseup   松开按键触发
        document.onkeyup =function(){
            document.body.style.backgroundColor = "";
        }

        // onkeypress   按下并松开按键触发
        document.onkeypress = function(en){
            document.body.style.backgroundColor = "#f90";
            console.log(en.keyCode);
        }

    </script>
</html>